#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

int main() {
    int n = 0;
    cin >> n;
    string s;
    cin >> s;
    unordered_map<char, vector<int>> hash;
    for (int i = 0; i < n; i++)
        hash[s[i]].push_back(i);
    vector<vector<int>> dp(n, vector<int>(n));
    int ret = 0;
    for (int j = 1; j < n; j++)
    {
        for (int i = 0; i < j; i++)
        {
            int a = s[j];
            if (s[i] != a)
            {
                for (auto k : hash[a])
                {
                    if (k > j)
                        dp[i][j] += dp[k][i] + 1;
                }
            }
            if (dp[i][j])
                ret += dp[i][j];
        }
    }
    cout << ret << endl;
    return 0;
}
